package com.zhanbo.zhanbowymusic.main.featured;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.mwx.baselib.base.BaseFragment;
import com.mwx.baselib.bean.ArtistAlbumBean;
import com.mwx.baselib.utils.DateUtils;
import com.mwx.baselib.utils.GlideUtils;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.databinding.FragmentSingerAlbumDetailsBinding;

import java.util.ArrayList;

/**
 * 专辑详情
 */
public class SingerAlbumDetailsFragment extends BaseFragment<FragmentSingerAlbumDetailsBinding> {
    private String[] mTitlesArrays = {"歌曲", "专辑详情"};
    private ArrayList<Fragment> fragments;
    private ArtistAlbumBean.ItemsDTO data;
    SingerAlbumPlayListFragment singerAlbumPlayListFragment;
    @Override
    protected Object getLayout() {
        return R.layout.fragment_singer_album_details;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        initData();
        initView();
        initListener();
    }

    @Override
    protected void initData() {
      data= (ArtistAlbumBean.ItemsDTO) getArguments().getSerializable("data");
      binding.tvAlbumName.setText(data.getAlbum().getName()+"");
      binding.tvAlbumName2.setText(data.getAlbum().getName()+"");
      GlideUtils.loadImageRounded10(_mActivity,data.getAlbum().getCoverUrl(),binding.ivHead);
      binding.tvCompany.setText(data.getAlbum().getCompany()+"");
      binding.tvDate.setText(DateUtils.ISO8601Format(data.getAlbum().getCreateTime()+""));

    }

    @Override
    protected void initView() {
        fragments = new ArrayList<>();
        singerAlbumPlayListFragment = SingerAlbumPlayListFragment.newInstance(data.getAlbumId());
        fragments.add(singerAlbumPlayListFragment);
        fragments.add(SingerAlbumTextFragment.newInstance(data));
        binding.vpSingerAlbumDetails.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });
        binding.tabSingerAlbumDetails.setViewPager(binding.vpSingerAlbumDetails, mTitlesArrays);
    }

    @Override
    protected void initListener() {
        binding.iconBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pop();
            }
        });
        binding.iconPlayAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //播放全部
                singerAlbumPlayListFragment.playAll();
            }
        });
    }

    public static SingerAlbumDetailsFragment newInstance(ArtistAlbumBean.ItemsDTO itemsDTO) {

        Bundle args = new Bundle();
        args.putSerializable("data",itemsDTO);
        SingerAlbumDetailsFragment fragment = new SingerAlbumDetailsFragment();
        fragment.setArguments(args);
        return fragment;
    }
}
